/**
 * 
 */
package com.ruyipu.forum.item;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.json.JSONException;
import org.json.JSONObject;

import com.ruyipu.forum.interfaces.IItem;

/**
 * @author donald
 * 
 */
public class Discussion implements Serializable, IItem {
	
	public static final String TAG = Discussion.class.getSimpleName();
	public static final String NAME = Discussion.class.getName();
	
	private static final String DISCUSSION_ID = "DiscussionID";
	private static final String DISCUSSION_NAME = "DiscussionName";
	private static final String COUNT_COMMENT = "CountComments";
	private static final String CATEGORY_NAME = "CategoryName";
	private static final String FIRST_NAME = "FirstName";
	private static final String FIRST_PHOTO = "FirstPhoto";
	private static final String DATE_INSERTED = "DateInserted";
	private static final String IS_ANNOUNCEMENT = "IsAnnounce";
	private static final String BODY = "DiscussionBody";
	private static final String IP = "InsertIPAddress";
	private static final String BOOKMARKED = "Bookmarked";

	private static final long serialVersionUID = -7766768700242418786L;
	
	private int iId = 0;
	private String sName = "";
	private String sBody = "";
	private int iCountComment = 0;
	private String sCategoryName = "";
	private String sFirstName = "";
	private String sFirstPhoto = "";
	private Date dDateInserted = null;
	private String sIP;
	private boolean bIsAnnouncement = false;
	private boolean bBookmarked = false;

	public Discussion() {
	}

	public void parse(JSONObject jsonObject) throws JSONException {
		iId = jsonObject.getInt(DISCUSSION_ID);
		sName = jsonObject.getString(DISCUSSION_NAME);
		sBody = jsonObject.getString(BODY);
		iCountComment = jsonObject.getInt(COUNT_COMMENT);
		sCategoryName = jsonObject.getString(CATEGORY_NAME);
		sFirstName = jsonObject.getString(FIRST_NAME);
		sFirstPhoto = jsonObject.getString(FIRST_PHOTO);
		sIP = jsonObject.getString(IP);
		SimpleDateFormat df = new SimpleDateFormat("yyyy-M-dd kk:mm:ss");
		try {
			dDateInserted = df.parse(jsonObject.getString(DATE_INSERTED));
		} catch (ParseException e) {
			dDateInserted = null;
		}
		bIsAnnouncement = jsonObject.getBoolean(IS_ANNOUNCEMENT);

		bBookmarked = jsonObject.getBoolean(BOOKMARKED);
	}

	// private String Type;
	// private String ForeignID;
	// private int CategoryID;
	// private int InsertUserID;
	// private int UpdateUserID;
	// private int LastCommentID;
	//
	// private String Format;
	// private String Tags;
	// private int CountBookmarks;
	// private int CountViews;
	// private Short Closed;
	// private Short Announce;
	// private Short Sink;
	//
	// private Date DateUpdated;
	// private String InsertIPAddress;
	// private String UpdateIPAddress;
	// private Date DateLastComment;
	// private float Score;
	// private String Attributes;
	// private int RegardingID;

	public int getId() {
		return iId;
	}

	public int getCountComment() {
		return iCountComment;
	}

	public String getCategoryName() {
		return sCategoryName;
	}

	public String getName() {
		return sName;
	}

	public String getFirstName() {
		return sFirstName;
	}
	
	public String getFirstPhoto() {
		return sFirstPhoto;
	}
	
	public String getIP() {
		return sIP;
	}

	public String getDate() {
		if (dDateInserted != null) {
			return dDateInserted.toString().substring(4, 10);
		}
		return null;
	}

	public boolean getBookmarked() {
		return bBookmarked;
	}

	public String getContent() {
		return sBody;
	}

	public boolean isAnnouncement() {
		return bIsAnnouncement;
	}

	public boolean isBookmarked() {
		return bBookmarked;
	}
}
